<template>
  <!--普通用户的首页框架-->
  <el-container class="index">
    <el-header class="header">
      <el-row>
        <!--左侧logo区域-->
        <el-col :span="12" class="logo-container">
          <span class="title">学生成绩录入管理系统</span>
        </el-col>
        <!--右侧用户信息区域-->
        <el-col :span="12" class="user">
          <img class="user-img" :src="myStore.state.userInfo.avatar" alt="" />
          <span style="margin-right: 10px">{{
            myStore.state.userInfo.username
          }}</span>
          <el-link :underline="false" type="primary" @click="logout">
            <el-icon><switch-button /></el-icon>
          </el-link>
        </el-col>
      </el-row>
    </el-header>
    <el-container class="container">
      <el-aside class="lefter">
        <el-scrollbar>
          <el-menu
            router
            class="el-menu-vertical"
            background-color="#324057"
            text-color="#fff"
            active-text-color="#409eff"
          >
           <el-menu-item index="/app/order">
              <el-icon><document /></el-icon>
              <span>订单管理</span>
            </el-menu-item>

            <el-menu-item index="/app/product">
              <el-icon><Bell /></el-icon>
              <span>商品管理</span>
            </el-menu-item>
          <el-menu-item index="/app/user">
              <el-icon> <User /> </el-icon>
              <span>用户管理</span>
            </el-menu-item>
            <el-menu-item index="3" @click="logout">
              <el-icon> <SwitchButton /> </el-icon>退出系统
            </el-menu-item>
          </el-menu>
        </el-scrollbar>
      </el-aside>
      <el-main class="content">
        <el-scrollbar>
          <!--通过router-view加载其他组件-->
          <router-view></router-view>
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
//注意：选项式api，不需要在<script>里面使用setup,兼容vue2.x写法
//引入路由实例(从封装的myRouter.js中导入)
import router from "../../router/myRouter.js";
import { useStore } from "vuex";
export default {
  name: "AppIndex",
  //定义响应数据
  data: function () {
    return {
      userInfo: {
        userId: "",
        loginId: "",
        userName: "",
      },
      myStore: useStore(),
    };
  },
  //使用生命周期函数
  mounted() {
    //路由到默认首页页面
    router.push("/app/order");
  },
  methods: {
    logout: function () {
      sessionStorage.removeItem("userInfo");
      router.replace("/");
    },
  },
};
</script>
<style lang="less" scoped>
/*定义index页面的布局及样式*/
.index {
  width: 100%;
  height: 100%;
}

/*头部样式*/
.header {
  box-sizing: border-box;
  width: 100%;
  height: 72px;
  min-width: 600px;

  padding: 5px;
  background: #324057;
  color: #fff;
  border-bottom: 1px solid #324057;
}

.logo-container {
  line-height: 60px;
  min-width: 400px;
}

.logo {
  height: 50px;
  width: 50px;
  margin-right: 5px;
  vertical-align: middle;
  display: inline-block;
}

.title {
  vertical-align: middle;
  font-size: 22px;
  letter-spacing: 3px;
}

.user {
  display: flex;
  justify-content: end;
  align-items: center;
  line-height: 60px;
  text-align: right;
  float: right;
  padding-right: 20px;
}

.user-img {
  margin-right: 10px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
}

.container {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  background-color: #ece8e8;
}

/*左侧菜单样式*/
.lefter {
  box-sizing: border-box;
  width: 220px;

  min-height: 100%;
  margin: 0;
  padding: 0;
  background-color: #00f2ff;
}
/* .el-scrollbar__wrap */
.lefter .el-scrollbar {
  background-color: #324057;
}
.el-menu {
  border: none;
}

.el-menu-vertical:not(.el-menu--collapse) {
  width: 220px;
  min-height: 400px;
  margin: 0;
  padding: 0;
}

.el-menu-vertical {
  margin: 0;
  width: 220px;
  margin: 0;
  padding: 0;
}

.el-submenu .el-menu-item {
  min-width: 220px;
}

.el-menu-item {
  width: 220px;
}

a {
  text-decoration: none;
}

.el-menu-item.is-active {
  background-color: #324057;
}

.content {
  padding: 20px;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
}
</style>
